package cn.cloudplug.friendsrecommend.util;

import cn.cloudplug.friendsrecommend.R;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class AddView {
	private Context context;
	private static int index=0;
	public enum Type{
		TEXTVIEW,EDITTEXT,CHECKBOX,RADOBUTTON,IMAGEVIEW,BUTTON;
	}
	public AddView(Context context){
		this.context=context;
	}
	public View createView(Type type,String text,int resId){
		LinearLayout.LayoutParams param=new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int)context.getResources().getDimension(R.dimen.reg_content_item_height));
		switch (type) {
		case TEXTVIEW:
			TextView tv=new TextView(context);
			tv.setId(index++);
			tv.setText(text);
			tv.setTextSize(20);
			tv.setGravity(Gravity.CENTER_VERTICAL);
			tv.setLayoutParams(param);
			return tv;
		case EDITTEXT:
			EditText et=new EditText(context);
			et.setId(index++);
			et.setPadding(20, 0, 0, 0);
			et.setTextSize(20);
			et.setBackgroundResource(R.drawable.edittext_frame);
			et.setGravity(Gravity.CENTER_VERTICAL);
			et.setLayoutParams(param);
			return et;
		case CHECKBOX:
			CheckBox cb=new CheckBox(context);
			cb.setId(index++);
			cb.setText(text);
			cb.setTextSize(20);
			cb.setGravity(Gravity.CENTER_VERTICAL);
			cb.setLayoutParams(param);
			return cb;
		case RADOBUTTON:
			RadioButton rb=new RadioButton(context);
			rb.setId(index++);
			rb.setText(text);
			rb.setTextSize(20);
			rb.setGravity(Gravity.CENTER_VERTICAL);
			rb.setLayoutParams(param);
			return rb;
		case BUTTON:
			LinearLayout.LayoutParams p1=new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int)context.getResources().getDimension(R.dimen.reg_content_item_height)+30);
			RelativeLayout rl=new RelativeLayout(context);
			rl.setLayoutParams(p1);
			RelativeLayout.LayoutParams rp=new android.widget.RelativeLayout.LayoutParams((int)context.getResources().getDimension(R.dimen.button_width),(int)context.getResources().getDimension(R.dimen.user_regist_login_item_height));
			rp.addRule(RelativeLayout.CENTER_HORIZONTAL,RelativeLayout.TRUE);
			rp.setMargins(0, 20, 0, 0);
			Button bt=new Button(context);
			bt.setId(index++);
			bt.setText("下一步");
			bt.setBackgroundResource(R.drawable.button_style);
			bt.setTextSize((float)context.getResources().getDimension(R.dimen.regist_login_button_text_size));
			bt.setTextColor(0xFFFFFFFF);
			bt.setLayoutParams(rp);
			rl.addView(bt);
			return rl; 
		}
		return null;
	}
}
